clear all
set more off
capture log close
pause on


*set scheme s1color
*grstyle init
*grstyle set nogrid


/* SC */ capture use "/Users/robertchaudoin/Dropbox/Complementarity ZC/Georgia Data Sept 2019/ICC_with_NR_7.09.19.dta", clear
/* KZ */ capture use "/Users/kelebogilezvobgo/Dropbox/Complementarity/Georgia Data Sept 2019/ICC_with_NR_7.09.19.dta", clear

keep if exp != .



***
* Control Variable Setup
***

gen female = .
replace female = 1 if sex == 2
replace female = 0 if sex == 1

gen colortv = d4_2
replace colortv = . if colortv == -1
gen computer = d4_8
gen smartphone = d4_3
gen car = d4_5

gen displaced = d5
replace displaced = . if displaced == -1

gen edu_postsecond = 0
replace edu_postsecond = 1 if d2 > 3

gen enoughmoney_scale = .
replace enoughmoney_scale = d3 if d3 > 0

gen enoughforfoodclothes = .
replace enoughforfoodclothes = 1 if d3 >= 3
replace enoughforfoodclothes = 0 if d3 == 1 | d3 == 2
replace enoughforfoodclothes = . if d3 < 0

gen capital = .
replace capital = 1 if substratum == 10
replace capital = 0 if substratum != 10

gen urban = .
replace urban = 1 if substratum == 21 | substratum == 22 | substratum == 23 | substratum == 24
replace urban = 0 if substratum == 10 | substratum > 24

gen rural = .
replace rural = 1 if substratum == 31 | substratum == 32 | substratum == 33 | substratum == 34
replace rural = 0 if substratum < 30



***
* Treatment / outcome variables setup
***

gen treatment = .
replace treatment = 1 if exp == 2
replace treatment = 0 if exp == 1

* icc1 is domestic legal system capable
gen legalsystem_capable_nodkrta = .
replace legalsystem_capable_nodkrta = 1 if icc1 == 3 | icc1 == 4
replace legalsystem_capable_nodkrta = 0 if icc1 == 1 | icc1 == 2

gen legalsystem_capable = legalsystem_capable_nodkrta
replace legalsystem_capable = 0 if icc1 == -1 | icc1 == -2

* icc2 is support for ICC inv.
gen invsupport_agree = .
replace invsupport_agree = 1 if icc2 == 3 | icc2 == 4
replace invsupport_agree = 0 if icc2 == -1 | icc2 == 1 | icc2 == 2
replace invsupport_agree = . if icc2 == -2 | icc2 == -9

gen invsupport_agree_nodkrta = invsupport_agree
replace invsupport_agree_nodkrta = . if icc2 == -1

*tab icc2, nolab
gen iccsupport_num = .
replace iccsupport_num = 0 if icc2 == 1
replace iccsupport_num = 1 if icc2 == 2
replace iccsupport_num = 2 if icc2 == -1
replace iccsupport_num = 3 if icc2 == 3
replace iccsupport_num = 4 if icc2 == 4

* icc3 is better for Geo. inv.
gen georgiabetter_agree = .
replace georgiabetter_agree = 1 if icc3 == 3 | icc3 == 4
replace georgiabetter_agree = 0 if icc3 == -1 | icc3 == 1 | icc3 == 2
replace georgiabetter_agree = . if icc3 == -2 | icc3 == -9

gen georgiabetter_agree_nodkrta = georgiabetter_agree
replace georgiabetter_agree_nodkrta = . if icc3 == -1

gen gabetter_num = .
replace gabetter_num = 0 if icc3 == 1
replace gabetter_num = 1 if icc3 == 2
replace gabetter_num = 2 if icc3 == -1
replace gabetter_num = 3 if icc3 == 3
replace gabetter_num = 4 if icc3 == 4


gen employed = 0
replace employed = 1 if d1 >= 1 & d1 <= 3 

* Outsheeting for the Bowers/Hansen test in R
capture export delimited using "/Users/robertchaudoin/Dropbox/Complementarity ZC/Georgia Data Sept 2019/geo_working_2021_07_02.csv", replace
capture export delimited using "/Users/kelebogilezvobgo/Dropbox/Complementarity/Georgia Data Sept 2019/geo_working_2021_07_02.csv", replace

* Quick computer balance check
reg treatment computer

* Label variables
label variable treatment "Compl." 
label variable invsupport_agree_nodkrta "Support ICC Inv., no DKRTA" 
label variable invsupport_agree "Support ICC Inv." 
label variable georgiabetter_agree_nodkrta "Support Geo. Inv., no DKRTA" 
label variable georgiabetter_agree "Support Geo. Inv."
label variable legalsystem_capable_nodkrta "Leg. Sys. Cap., no DKRTA" 
label variable legalsystem_capable "Leg. Sys. Cap." 
label variable female "Female" 
label variable displaced "Displaced" 
label variable enoughforfoodclothes "Enough Money" 
label variable enoughmoney_scale "Enough Money Scale" 
label variable capital "Capital" 
label variable urban "Urban" 
label variable rural "Rural" 
label variable edu_postsecond "Post-Sec. Edu." 
label variable age "Age"



***
* Descriptive stats and balance
***

global ctrls female age edu_postsecond enoughmoney_scale capital urban rural
	* This list matches the R regressions
global dvs invsupport_agree_nodkrta invsupport_agree georgiabetter_agree_nodkrta georgiabetter_agree

estpost su treatment $dvs $ctrls
	est store full
estpost su treatment $dvs $ctrls if treatment == 1
	est store tmt
estpost su treatment $dvs $ctrls if treatment == 0
	est store ctrl

*	Making summary stats table, means only, full - treatment only - control only
	esttab full tmt ctrl ///
		using "/Users/robertchaudoin/Dropbox/Complementarity ZC/Georgia Data Sept 2019/meanstats_tmtctrl_geo.tex", replace ///
		cells(mean(fmt(2))) nodep nonum  ///
		mtitle("Full" "Treatment" "Control") ///
		coeflabels(treatment "Compl." invsupport_agree_nodkrta "Support ICC Inv. NoDKRTA" invsupport_agree "Support ICC Inv." georgiabetter_agree_nodkrta "Support Geo. Inv. NoDKRTA" georgiabetter_agree "Support Geo. Inv." ///
		female "Female" displaced "Displaced" enoughmoney_scale "Enough mon." capital "Capital" urban "Urban" rural "Rural" edu_postsecond "Post-Sec. Ed." age "Age")
	
	
	
***
* Simple analysis of treatment effects
***	
	
* Histogram, support for ICC investigations by treatment
twoway (histogram icc2 if treatment == 0 & icc2 >= -2, discr frac lcolor(gray) fcolor(gray) xlabel(-2 "RTA" -1 "DK" 1 "Strongly disagree" 2 "Somewhat disagree" 3 "Somewhat agree" 4 "Strongly agree", labs(vsmall) angle(-45))) ///
	(histogram icc2 if treatment == 1 & icc2 >= -2, discr frac fcolor(none) lcolor(black)), legend(order(1 "Control" 2 "Treatment")) ///
	xtitle("Support ICC Inv.") ylab(, nogrid) bgcolor(white) graphregion(color(white))
		*graph export "/Users/robertchaudoin/Dropbox/Complementarity ZC/Georgia Data Sept 2019/hist_iccinv_bytmt_geo.eps", as(eps) preview(off) replace
		graph export "/Users/kelebogilezvobgo/Dropbox/Complementarity/Georgia Data Sept 2019/hist_iccinv_bytmt_geo.eps", as(eps) preview(off) replace
	
* Histogram, Georgia better by treatment
twoway (histogram icc3 if treatment == 0 & icc3 >= -2, discr frac lcolor(gray) fcolor(gray) xlabel(-2 "RTA" -1 "DK" 1 "Strongly disagree" 2 "Somewhat disagree" 3 "Somewhat agree" 4 "Strongly agree", labs(vsmall) angle(-45))) ///
	(histogram icc3 if treatment == 1 & icc3 >= -2, discr frac fcolor(none) lcolor(black)), legend(order(1 "Control" 2 "Treatment")) ///
	xtitle("Support Geo. Inv.") ylab(, nogrid) bgcolor(white) graphregion(color(white))
		*graph export "/Users/robertchaudoin/Dropbox/Complementarity ZC/Georgia Data Sept 2019/hist_geoinv_bytmt.eps", as(eps) preview(off) replace
		graph export "/Users/kelebogilezvobgo/Dropbox/Complementarity/Georgia Data Sept 2019/hist_geoinv_bytmt.eps", as(eps) preview(off) replace

* Cross tabs
tab icc2 treatment
tab icc3 treatment



***	
* Treatment effects
***	


** Bivariate regressions **

* OLS
eststo clear
qui reg invsupport_agree treatment
	est2vec slim_reg_geo, replace name(iccinv1) vars(treatment _cons)
qui reg invsupport_agree_nodkrta treatment
	est2vec regnodkrta, replace name(regnodkrta) addto(slim_reg_geo)
qui reg georgiabetter_agree treatment
	est2vec geoinv, replace name(geoinv1) addto(slim_reg_geo)
qui reg georgiabetter_agree_nodkrta treatment
	est2vec regnodkrta, replace name(garegnodkrta) addto(slim_reg_geo)
	
	*est2tex slim_reg_geo, preserve label path("/Users/robertchaudoin/Dropbox/Complementarity ZC/Georgia Data Sept 2019/") mark(starb) fancy replace levels(90 95 99) leadzero
	est2tex slim_reg_geo, preserve label path("/Users/kelebogilezvobgo/Dropbox/Complementarity/Georgia Data Sept 2019/") mark(starb) fancy replace levels(90 95 99) leadzero

* Logit
eststo clear
qui logit invsupport_agree treatment
	est2vec slim_logit_geo, replace name(iccinv1) vars(treatment _cons)
qui logit invsupport_agree_nodkrta treatment
	est2vec logitnodkrta, replace name(logitnodkrta) addto(slim_logit_geo)
qui logit georgiabetter_agree treatment
	est2vec logitgeoinv, replace name(logitgeoinv1) addto(slim_logit_geo)
qui logit georgiabetter_agree_nodkrta treatment
	est2vec logitnodkrta, replace name(galogitnodkrta) addto(slim_logit_geo)
	
	*est2tex slim_logit_geo, preserve label path("/Users/robertchaudoin/Dropbox/Complementarity ZC/Georgia Data Sept 2019/") mark(starb) fancy replace levels(90 95 99) leadzero
	est2tex slim_logit_geo, preserve label path("/Users/kelebogilezvobgo/Dropbox/Complementarity/Georgia Data Sept 2019/") mark(starb) fancy replace levels(90 95 99) leadzero
	
	

** Multivariate regressions **


* OLS
eststo clear
qui reg invsupport_agree treatment legalsystem_capable $ctrls2
	est2vec full_reg_geo, replace name(iccinv1) vars(treatment legalsystem_capable $ctrls2 _cons)
qui reg invsupport_agree_nodkrta treatment legalsystem_capable_nodkrta $ctrls2
	est2vec regnodkrta, replace name(regnodkrta) addto(full_reg_geo)
qui reg georgiabetter_agree treatment legalsystem_capable $ctrls2
	est2vec geoinv, replace name(geoinv1) addto(full_reg_geo)
qui reg georgiabetter_agree_nodkrta treatment legalsystem_capable_nodkrta $ctrls2
	est2vec regnodkrta, replace name(garegnodkrta) addto(full_reg_geo)
	
	*est2tex full_reg_geo, preserve label path("/Users/robertchaudoin/Dropbox/Complementarity ZC/Georgia Data Sept 2019/") mark(starb) fancy replace levels(90 95 99) leadzero
	est2tex full_reg_geo, preserve label path("/Users/kelebogilezvobgo/Dropbox/Complementarity/Georgia Data Sept 2019/") mark(starb) fancy replace levels(90 95 99) leadzero

	
	
** Interaction term regressions **												Stephen, my version of STATA was acting up, so the syntax below is different for the interaction mods.


gen tmt_lsc = treatment*legalsystem_capable
gen tmt_lscnodkrta = treatment*legalsystem_capable_nodkrta

label variable tmt_lsc "Compl. * Leg. Sys. Cap."
label variable tmt_lscnodkrta "Compl. * Leg. Sys. Cap., no DKRTA"

eststo clear
eststo A1: reg invsupport_agree treatment legalsystem_capable tmt_lsc
eststo A2: reg invsupport_agree_nodkrta treatment legalsystem_capable_nodkrta tmt_lscnodkrta
eststo A3: reg invsupport_agree treatment legalsystem_capable tmt_lsc $ctrls2
eststo A4: reg invsupport_agree_nodkrta treatment legalsystem_capable_nodkrta tmt_lscnodkrta $ctrls2

eststo B1: reg georgiabetter_agree treatment legalsystem_capable tmt_lsc
eststo B2: reg georgiabetter_agree treatment legalsystem_capable_nodkrta tmt_lscnodkrta
eststo B3: reg georgiabetter_agree treatment legalsystem_capable tmt_lsc $ctrls2
eststo B4: reg georgiabetter_agree treatment legalsystem_capable_nodkrta tmt_lscnodkrta $ctrls2

esttab A1 A2 A3 A4 B1 B2 B3 B4 using "/Users/kelebogilezvobgo/Dropbox/Complementarity/Georgia Data Sept 2019/int_reg_geo.tex", label b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) replace
